/**
 * IBaderUtil.java : [com.ibader.eclipse.test.utils] Created on 2009. 5. 17.
 *
 * Copyright (c) 2009 Raccoon Project Team.
 * Seoul, Korea
 * All rights reserved.
 *
 */
package com.ibader.eclipse.test.utils;

import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Display;

/**
 * @author KimJungSu
 * @version
 */
public class IBaderUtil {

	/**
	 *
	 * @param waitTimeMillis
	 */
	public static void waitForJobs(long waitTimeMillis) {
		while (Platform.getJobManager().currentJob() != null) {
			delay(waitTimeMillis);
		}
	}

	/**
	 *
	 * @param waitTimeMillis
	 */
	private static void delay(long waitTimeMillis) {
		Display	display = Display.getCurrent();

		if (display != null) {
			long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
			while (System.currentTimeMillis() < endTimeMillis) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
			display.update();
		}
		else {
			try {
				Thread.sleep(waitTimeMillis);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
